<template>
  <view class="mine-container" :style="{height: `${windowHeight}px`}">
    <!--顶部个人信息栏-->
    <view class="header-section">
      <view class="flex padding justify-between">
        <view class="flex align-center">
          <view v-if="!avatar" class="cu-avatar xl round bg-white">
            <view class="iconfont icon-people text-gray icon"></view>
          </view>
          <image v-if="avatar" @click="handleToAvatar" :src="avatar" class="cu-avatar xl round" mode="widthFix">
          </image>
          <view v-if="!name" @click="handleToLogin" class="login-tip">
            点击登录
          </view>
          <view v-if="name" @click="handleToInfo" class="user-info">
            <view class="u_title">{{ name }}</view>
            <view class="u_subtitle">{{ userProfile.age }}岁 | {{ userProfile.activityLevel }}</view>
          </view>
        </view>
        <view @click="handleToInfo" class="flex align-center">
          <text>个人信息</text>
          <view class="iconfont icon-right"></view>
        </view>
      </view>
    </view>

    <view class="content-section">
      <!-- 今日饮食数据 -->
      <view class="today-stats">
        <view class="stats-title">今日饮食</view>
        <view class="stats-grid">
          <view class="stat-item">
            <text class="stat-value">{{ todayStats.calories }}</text>
            <text class="stat-label">千卡</text>
          </view>
          <view class="stat-item">
            <text class="stat-value">{{ todayStats.dishes }}</text>
            <text class="stat-label">道菜</text>
          </view>
          <view class="stat-item">
            <text class="stat-value">{{ todayStats.protein }}g</text>
            <text class="stat-label">蛋白质</text>
          </view>
          <view class="stat-item">
            <text class="stat-value">{{ todayStats.rating }}</text>
            <text class="stat-label">平均评分</text>
          </view>
        </view>
      </view>

      <view class="menu-list">
        <view class="list-cell list-cell-arrow" @click="handleToProfile">
          <view class="menu-item-box">
            <uni-icons type="person-filled" size="20" color="#1890ff" class="menu-icon" />
            <view>个人信息</view>
          </view>
        </view>
        <view class="list-cell list-cell-arrow" @click="handleToDietHabits">
          <view class="menu-item-box">
            <uni-icons type="gear-filled" size="20" color="#52c41a" class="menu-icon" />
            <view>饮食习惯</view>
          </view>
        </view>
        <view class="list-cell list-cell-arrow" @click="handleToFavorites">
          <view class="menu-item-box">
            <uni-icons type="heart-filled" size="20" color="#ff4d4f" class="menu-icon" />
            <view>我的收藏</view>
          </view>
        </view>
        <view class="list-cell list-cell-arrow" @click="handleToClicks">
          <view class="menu-item-box">
            <uni-icons type="eye-filled" size="20" color="#722ed1" class="menu-icon" />
            <view>浏览记录</view>
          </view>
        </view>
        <view class="list-cell list-cell-arrow" @click="handleToHistory">
          <view class="menu-item-box">
            <uni-icons type="calendar" size="20" color="#1890ff" class="menu-icon" />
            <view>饮食记录</view>
          </view>
        </view>
        <view class="list-cell list-cell-arrow" @click="handleToGoals">
          <view class="menu-item-box">
            <uni-icons type="flag-filled" size="20" color="#faad14" class="menu-icon" />
            <view>健康目标</view>
          </view>
        </view>
        <view class="list-cell list-cell-arrow" @click="handleToSetting">
          <view class="menu-item-box">
            <uni-icons type="gear" size="20" color="#666" class="menu-icon" />
            <view>设置</view>
          </view>
        </view>
      </view>

    </view>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        name: this.$store.state.user.name,
        userProfile: {
          age: 25,
          activityLevel: '轻度活动'
        },
        todayStats: {
          calories: 1580,
          dishes: 8,
          protein: 65,
          rating: 4.2
        }
      }
    },
    computed: {
      avatar() {
        return this.$store.state.user.avatar
      },
      windowHeight() {
        return uni.getSystemInfoSync().windowHeight - 50
      }
    },
    methods: {
      handleToInfo() {
        this.$tab.navigateTo('/pages/mine/info/index')
      },
      handleToProfile() {
        this.$tab.navigateTo('/pages/mine/profile/index')
      },
      handleToDietHabits() {
        this.$tab.navigateTo('/pages/mine/diet-habits/index')
      },
      handleToHistory() {
        this.$tab.navigateTo('/pages/mine/history/index')
      },
      handleToGoals() {
        this.$tab.navigateTo('/pages/mine/goals/index')
      },
      handleToFavorites() {
        this.$tab.navigateTo('/pages/mine/favorites/index')
      },
      handleToClicks() {
        this.$tab.navigateTo('/pages/mine/clicks/index')
      },
      handleToSetting() {
        this.$tab.navigateTo('/pages/mine/setting/index')
      },
      handleToLogin() {
        this.$tab.reLaunch('/pages/login')
      },
      handleToAvatar() {
        this.$tab.navigateTo('/pages/mine/avatar/index')
      }
    }
  }
</script>

<style lang="scss" scoped>
  page {
    background-color: #f5f6f7;
  }

  .mine-container {
    width: 100%;
    height: 100%;


    .header-section {
      padding: 15px 15px 45px 15px;
      background-color: #3c96f3;
      color: white;

      .login-tip {
        font-size: 18px;
        margin-left: 10px;
      }

      .cu-avatar {
        border: 2px solid #eaeaea;

        .icon {
          font-size: 40px;
        }
      }

      .user-info {
        margin-left: 15px;

        .u_title {
          font-size: 18px;
          line-height: 30px;
        }

        .u_subtitle {
          font-size: 14px;
          opacity: 0.8;
          margin-top: 5px;
        }
      }
    }

    .content-section {
      position: relative;
      top: -50px;

      .today-stats {
        margin: 15px 15px;
        padding: 20px;
        border-radius: 8px;
        background-color: white;

        .stats-title {
          font-size: 16px;
          font-weight: bold;
          margin-bottom: 15px;
          color: #333;
        }

        .stats-grid {
          display: flex;
          justify-content: space-between;
        }

        .stat-item {
          text-align: center;
          flex: 1;

          .stat-value {
            display: block;
            font-size: 18px;
            font-weight: bold;
            color: #1890ff;
            margin-bottom: 5px;
          }

          .stat-label {
            font-size: 12px;
            color: #666;
          }
        }
      }
    }
  }

  .menu-item-box {
    display: flex;
    align-items: center;
    
    .menu-icon {
      margin-right: 15rpx;
    }
  }

  .list-cell {
    padding: 25rpx 30rpx;
    border-bottom: 1rpx solid #f0f0f0;
    
    &:last-child {
      border-bottom: none;
    }
  }

  .list-cell-arrow::after {
    content: '';
    position: absolute;
    right: 30rpx;
    top: 50%;
    transform: translateY(-50%);
    width: 12rpx;
    height: 12rpx;
    border-top: 2rpx solid #ccc;
    border-right: 2rpx solid #ccc;
    transform: translateY(-50%) rotate(45deg);
  }

  .menu-list {
    background: white;
    border-radius: 16rpx;
    margin: 0 30rpx;
    position: relative;
  }
</style>
